package com.atguigu.spzx.manager.controller;

import com.atguigu.spzx.manager.service.impl.CategoryServiceImpl;
import com.atguigu.spzx.common.result.Result;
import com.atguigu.spzx.manager.vo.category.CategoryQueryRespVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * <p>
 * CategoryController
 * </p>
 *
 * @author flyduck
 * @since 2023/10/28
 */
@Api(tags = "分类管理接口")
@RestController
@RequestMapping("/admin/product/category")
public class CategoryController {

    @Autowired
    private CategoryServiceImpl categoryService;

    @ApiOperation("导入数据")
    @PostMapping("/importCategoryList")
    public Result importCategoryList(MultipartFile file){
        categoryService.importCategoryList(file);
        return Result.ok();
    }

    @ApiOperation("导出数据")
    @GetMapping("/exportCategoryList")
    public void exportCategoryList(HttpServletResponse response){
        categoryService.exportCategoryList(response);
    }

    @ApiOperation("根据parentId查询分类列表")
    @GetMapping("/getCategoryListByParentId/{parentId}")
    public Result<List<CategoryQueryRespVo>> findCategoryList(@PathVariable Long parentId){
        List<CategoryQueryRespVo> list = categoryService.getCategoryListByParentId(parentId);
        return Result.ok(list);
    }
}
